package com.olinsports.system.olinsportssystem.service;

import com.olinsports.system.olinsportssystem.model.SavingDetail;
import com.olinsports.system.olinsportssystem.model.StmUsr;
import com.olinsports.system.olinsportssystem.repository.SavingDetailRepository;
import com.olinsports.system.olinsportssystem.repository.StmUsrRepository;
import com.olinsports.system.olinsportssystem.util.PageUtil;
import com.olinsports.system.olinsportssystem.util.SavingDetailExcel;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/7/22.
 */
@Service
public class StmUsrService {
    @Autowired
    private StmUsrRepository stmUsrRepository;
    @Autowired
    private HttpServletRequest request;

    public String singIn(String usrName, String password, ModelMap modelMap){
        StmUsr stmUsr = stmUsrRepository.selectByUsrName(usrName);
        if(stmUsr != null ){
            if(stmUsr.getUsrPassword().equals(password)){
                request.getSession().setAttribute("stmUsr",stmUsr);
                modelMap.addAttribute("roleName",stmUsr.getRoleName());
                return "index";
            } else {
                return "login";
            }
        } else {
            return "login";
        }
    }
    public List<StmUsr> selectAll(){

        return stmUsrRepository.selectAll();
    }

    public int insertAll(StmUsr stmUsr){
        stmUsr.setRoleName("normal");
        return stmUsrRepository.insertAll(stmUsr);
    }

}
